package com.hjm.project.agentInfo.record.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.agentInfo.record.domain.ClientRecord;
import com.hjm.project.agentInfo.record.service.IClientRecordService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 商户操作记录Controller
 * 
 * @author LOVE
 * @date 2020-11-23
 */
@Controller
@RequestMapping("/agentInfo/record")
public class ClientRecordController extends BaseController
{
    private String prefix = "agentInfo/record";

    @Autowired
    private IClientRecordService clientRecordService;

    @RequiresPermissions("agentInfo:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询商户操作记录列表
     */
    @RequiresPermissions("agentInfo:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClientRecord clientRecord)
    {
        startPage();
        List<ClientRecord> list = clientRecordService.selectClientRecordList(clientRecord);
        return getDataTable(list);
    }

    /**
     * 导出商户操作记录列表
     */
    @RequiresPermissions("agentInfo:record:export")
    @Log(title = "商户操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClientRecord clientRecord)
    {
        List<ClientRecord> list = clientRecordService.selectClientRecordList(clientRecord);
        ExcelUtil<ClientRecord> util = new ExcelUtil<ClientRecord>(ClientRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增商户操作记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户操作记录
     */
    @RequiresPermissions("agentInfo:record:add")
    @Log(title = "商户操作记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClientRecord clientRecord)
    {
        return toAjax(clientRecordService.insertClientRecord(clientRecord));
    }

    /**
     * 修改商户操作记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClientRecord clientRecord = clientRecordService.selectClientRecordById(id);
        mmap.put("clientRecord", clientRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户操作记录
     */
    @RequiresPermissions("agentInfo:record:edit")
    @Log(title = "商户操作记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClientRecord clientRecord)
    {
        return toAjax(clientRecordService.updateClientRecord(clientRecord));
    }

    /**
     * 删除商户操作记录
     */
    @RequiresPermissions("agentInfo:record:remove")
    @Log(title = "商户操作记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clientRecordService.deleteClientRecordByIds(ids));
    }
}
